package com.ruoyi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.domain.JkGroupUser;
import com.ruoyi.mapper.JkGroupUserMapper;
import com.ruoyi.service.IJkGroupUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 推送组用户Service业务层处理
 *
 * @author ruoyi
 * @date 2023-09-06
 */
@Service
public class JkGroupUserServiceImpl extends ServiceImpl<JkGroupUserMapper,JkGroupUser> implements IJkGroupUserService
{
    @Autowired
    private JkGroupUserMapper jkGroupUserMapper;

    /**
     * 查询推送组用户
     *
     * @param id 推送组用户主键
     * @return 推送组用户
     */
    @Override
    public JkGroupUser selectJkGroupUserById(Long id)
    {
        return jkGroupUserMapper.selectJkGroupUserById(id);
    }

    /**
     * 查询推送组用户列表
     *
     * @param jkGroupUser 推送组用户
     * @return 推送组用户
     */
    @Override
    public List<JkGroupUser> selectJkGroupUserList(JkGroupUser jkGroupUser)
    {
        return jkGroupUserMapper.selectJkGroupUserList(jkGroupUser);
    }

    /**
     * 新增推送组用户
     *
     * @param jkGroupUser 推送组用户
     * @return 结果
     */
    @Override
    public int insertJkGroupUser(JkGroupUser jkGroupUser)
    {
        jkGroupUser.setCreateTime(DateUtils.getNowDate());
        return jkGroupUserMapper.insertJkGroupUser(jkGroupUser);
    }

    /**
     * 修改推送组用户
     *
     * @param jkGroupUser 推送组用户
     * @return 结果
     */
    @Override
    public int updateJkGroupUser(JkGroupUser jkGroupUser)
    {
        return jkGroupUserMapper.updateJkGroupUser(jkGroupUser);
    }

    /**
     * 批量删除推送组用户
     *
     * @param ids 需要删除的推送组用户主键
     * @return 结果
     */
    @Override
    public int deleteJkGroupUserByIds(Long[] ids)
    {
        return jkGroupUserMapper.deleteJkGroupUserByIds(ids);
    }

    /**
     * 删除推送组用户信息
     *
     * @param id 推送组用户主键
     * @return 结果
     */
    @Override
    public int deleteJkGroupUserById(Long id)
    {
        return jkGroupUserMapper.deleteJkGroupUserById(id);
    }

    @Override
    public boolean insertList(ArrayList<JkGroupUser> addList) {
        return this.saveBatch(addList);
    }

    @Override
    public int deleteJkGroupUserByGroupId(Long id) {
        return this.baseMapper.delete(new QueryWrapper<JkGroupUser>().eq("group_id",id));
    }

    @Override
    public JkGroupUser selectByGroupIdAndUserId(JkGroupUser groupUser) {
        QueryWrapper<JkGroupUser> qw = new QueryWrapper<>();
        qw.eq(groupUser.getGroupId()!=null,"group_id",groupUser.getGroupId());
        qw.eq(groupUser.getUserId()!=null,"user_id",groupUser.getUserId());
        return this.baseMapper.selectOne(qw);
    }

    @Override
    public int deleteJkGroupUserByGroupIdAndUserId(JkGroupUser jkGroupUser) {
        QueryWrapper<JkGroupUser> qw = new QueryWrapper<>();
        qw.eq(jkGroupUser.getGroupId()!=null,"group_id",jkGroupUser.getGroupId());
        qw.eq(jkGroupUser.getUserId()!=null,"user_id",jkGroupUser.getUserId());
        return this.baseMapper.delete(qw);
    }
}
